<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="/Public/css/bootstrap.min.css" rel="stylesheet">
    <script src="/Public/js/jquery-1.11.1.min.js"></script>
    <script src="/Public/js/bootstrap.min.js"></script>
    <style>
        html,body,ul,ul li{margin: 0;padding: 0;border:0;}
        ul{list-style: none;}
        ul a{display: block;text-decoration: none;}
        ul a:hover{text-decoration: underline;}

        .a{
            background:url("/test/xiangmu/images/xinwen.png") center no-repeat;
            height: 998px;
            position: relative;
        }
        .b{
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -500px;
            margin-left: -30px;
        }

        .u:after{content: " ";display: table;clear: both}

        .imgs-div{margin: 10px 0;padding: 5px}
        .img-div{
            float: left;
            width: 200px;
            margin: 5px;
            height: 230px;
            border: 1px solid gray;text-align: center;
        }
        .img-div>img{display: block;width: 180px;margin:10px auto 5px;height: 180px}
    </style>
</head>
<body>
<div class="a">
    <div class="b"><h2 style=" font-family: MS PGothic;">新闻</h2></div>
    <div class="panel panel-primary" style="width: 50%;position: absolute;top:50%;left: 50%;margin-left: -370px;margin-top: -370px">
        <div class="panel-heading" >
            <span><a href="<?php echo U('/Xm/xinwen');?>" style="color: white">新闻主页</a></span>
        </div>
        <div class="panel-body u" style="padding-left: 50px">
            <div class="imgs-div"></div>
        </div>
    </div>
</div>
<script>
    var imgsDiv=$('.imgs-div');
    $.get('<?php echo U("Xm/shuaxin");?>',function(resp){
        showImages(resp)
    });

    function showImages(imgNames){
        for(var i=0;i<imgNames.length;i++){
            addImage(imgNames[i]);
        }
    }

    function addImage(imgName){
        var imgDiv=$('<div>',{'class':'img-div'});
        imgDiv.append($('<img>',{src:'/Ul/'+imgName}));
        imgDiv.append($('<button>',{html:'删除'}).click(deleteImg));
        imgDiv.appendTo(imgsDiv);
    }


    function deleteImg(){
        var me=$(this);
        var parent = me.parent('.img-div');
        var img = parent.children('img').attr('src');
        $.post('<?php echo U("Xm/delete");?>',{img:img},function(resp){
            if(resp.status){
                parent.remove();
            }else {
                alert(resp.message)
            }
        },'json')
    }

</script>
</body>
</html>